<?php

abstract class Db {

    public static $connection;

    public function __construct() {
        $this->connect();
    }

    function connect() {
        if (self::$connection) {
            return self::$connection;
        } else {
            self::$connection = mysql_connect(DB_HOST . ':' . DB_PORT, DB_USER, DB_PASS);
            mysql_select_db(DB_NAME, self::$connection);
            return self::$connection;
        }
    }

    function query($query) {
        mysql_query("set names 'utf8'");
        $ret = mysql_query($query, self::$connection);
        $data = array();
        while ($row = mysql_fetch_assoc($ret)) {
            $data[] = $row;
        }
        return $data;
    }

}
